using Assets.Scripts;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BigCubeControl : MonoBehaviour, IBaseCubeControl
{
    public CubeType CubeType { get; set; }
    public Vector3 dir { get; set; }
    public Vector3 org { get; set; }

    private void Awake()
    {
        CubeType = CubeType.Big;

        dir = BasicControl.GetDir();

        org = transform.position;
    }

    private void Update()
    {
        var dist = Vector3.Distance(transform.position, org);
        if (dist > 5) Destroy(gameObject);

        // if (!Input.GetMouseButton(0)) return;

        // var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        // RaycastHit hit;
        // if (!Physics.Raycast(ray, out hit)) return;
        // Debug.Log(hit.transform.gameObject.name);

        // if (hit.transform.gameObject.name != gameObject.name) return;

        // GetComponent<Rigidbody>().velocity = dir * 2000 * Time.deltaTime;
    }

    private void OnMouseDown() {
         GetComponent<Rigidbody>().velocity = dir * 1000 * Time.deltaTime;
    }

    private void OnCollisionEnter(Collision collision)
    {
        ResetPosition();
    }

    public void ResetPosition()
    {
        transform.position = org;
        GetComponent<Rigidbody>().velocity = Vector3.zero;
    }
}
